package sim

import (
	"context"

	"github.com/gogf/gf/v2/util/gconv"
	"github.com/sagoo-cloud/sagooiot/api/v1/sim"
	"github.com/sagoo-cloud/sagooiot/internal/model"
	"github.com/sagoo-cloud/sagooiot/internal/service"
)

var SimHistoryTraffic = cSimSim_history_traffic{}

type cSimSim_history_traffic struct{}

// GetSimHistoryTrafficList 获取列表
// func (u *cSimSim_history_traffic) GetSimHistoryTrafficList(ctx context.Context, req *sim.GetSimHistoryTrafficListReq) (res *sim.GetSimHistoryTrafficListRes, err error) {
// 	if req.Month != "" && req.Day != "" {
// 		err = gerror.New("月和年只能选一个")
// 		return
// 	}
// 	var reqData = new(model.GetSimHistoryTrafficListInput)
// 	gconv.Scan(req, &reqData)
// 	total, currentPage, dataList, err := service.SimSimHistoryTraffic().GetSimHistoryTrafficList(ctx, reqData)
// 	res = new(sim.GetSimHistoryTrafficListRes)
// 	gconv.Scan(dataList, &res.Data)
// 	res.PaginationRes.Total = total
// 	res.PaginationRes.CurrentPage = currentPage
// 	return
// }

// TopFLowReq 仪表盘 流量排行
func (u *cSimSim_history_traffic) TopFLow(ctx context.Context, req *sim.TopFLowReq) (res *sim.TopFlowRes, err error) {
	var in model.TopFlowIn
	gconv.Scan(req, &in)
	data, err := service.SimSimHistoryTraffic().TopFLow(ctx, &in)
	if err != nil {
		return
	}
	res = new(sim.TopFlowRes)
	gconv.Scan(data, res)
	return
}

// SimHTrafficStatis 仪表盘统计数据
func (u *cSimSim_history_traffic) SimHTrafficStatis(ctx context.Context, req *sim.SimHTrafficStatisReq) (res *sim.SimHTrafficStatisRes, err error) {
	res = new(sim.SimHTrafficStatisRes)
	data, err := service.SimSimHistoryTraffic().SimHTrafficStatis(ctx, req.Types)
	if err != nil {
		return
	}
	gconv.Scan(data, res)
	return
}

// SimHTrafficStatis 仪表盘统计数据
func (u *cSimSim_history_traffic) SimHistoryCharts(ctx context.Context, req *sim.SimHistoryChartsReq) (res *sim.SimHistoryChartsRes, err error) {
	out, err := service.SimSimHistoryTraffic().QueryHistoryTrafficByDate(ctx, req.Sdate, req.Edate, "", req.Types)
	if err != nil {
		return
	}
	res = &sim.SimHistoryChartsRes{}
	for _, v := range out {
		var tmp sim.TopFlowData
		gconv.Scan(v, &tmp)
		res.Data = append(res.Data, tmp)
	}
	return
}

// // GetSimHistoryTrafficById 获取指定ID数据
// func (u *cSimSim_history_traffic) GetSimHistoryTrafficById(ctx context.Context, req *sim.GetSimHistoryTrafficByIdReq) (res *sim.GetSimHistoryTrafficByIdRes, err error) {
// 	data, err := service.SimSimHistoryTraffic().GetSimHistoryTrafficById(ctx, req.Id)
// 	res = new(sim.GetSimHistoryTrafficByIdRes)
// 	gconv.Scan(data, &res)
// 	return
// }

// // AddSimHistoryTraffic 添加数据
// func (u *cSimSim_history_traffic) AddSimHistoryTraffic(ctx context.Context, req *sim.AddSimHistoryTrafficReq) (res *sim.AddSimHistoryTrafficRes, err error) {
// 	userInfo := service.Context().GetLoginUser(ctx)
// 	if userInfo == nil {
// 		err = gerror.New("未登录或TOKEN失效,请重新登录")
// 		return
// 	}
// 	var data = model.SimHistoryTrafficAddInput{}
// 	gconv.Scan(req, &data)
// 	// data.CreatedBy = userInfo.Id
// 	err = service.SimSimHistoryTraffic().AddSimHistoryTraffic(ctx, data)
// 	return
// }

// // EditSimHistoryTraffic 修改数据
// func (u *cSimSim_history_traffic) EditSimHistoryTraffic(ctx context.Context, req *sim.EditSimHistoryTrafficReq) (res *sim.EditSimHistoryTrafficRes, err error) {
// 	userInfo := service.Context().GetLoginUser(ctx)
// 	if userInfo == nil {
// 		err = gerror.New("未登录或TOKEN失效,请重新登录")
// 		return
// 	}
// 	var data = model.SimHistoryTrafficEditInput{}
// 	gconv.Scan(req, &data)
// 	// data.UpdateBy = userInfo.Id //如果需要保存信息，把这个打开
// 	err = service.SimSimHistoryTraffic().EditSimHistoryTraffic(ctx, data)
// 	return
// }

// // DeleteSimHistoryTraffic 删除数据
// func (u *cSimSim_history_traffic) DeleteSimHistoryTraffic(ctx context.Context, req *sim.DeleteSimHistoryTrafficReq) (res *sim.DeleteSimHistoryTrafficRes, err error) {
// 	if len(req.Ids) == 0 {
// 		err = gerror.New("ID参数错误")
// 	}
// 	err = service.SimSimHistoryTraffic().DeleteSimHistoryTraffic(ctx, req.Ids)
// 	return
// }
